#include <string>
#include <vector>
#include "article.h"
#include <unordered_map>	
#include "newsgroup.h"
	
using namespace std;
	

vector<pair<int, string>> newsgroup::getarticlenames(){
	vector<pair<int, string>> result;
	for(auto it = articles.begin(); it != articles.end(); ++it){
		result.push_back(make_pair((it->second).getarticleid(), (it->second).gettitle()));
	}
	return result;
}
	
pair<int, article> newsgroup::getarticle(int articleid){
	auto it = articles.find(articleid);
	if(it != articles.end()){
		return make_pair(0,it->second);
	}
	article a(0, "","","");
	return make_pair(2, a);
}
	
void newsgroup::addarticle(string title, string author, string text){
	++nextarticleid;
	articles.insert(make_pair(nextarticleid, article(nextarticleid, title, author, text)));
}

bool newsgroup::deletearticle(int articleid){
	return articles.erase(articleid);
}